<template>
  <el-form :model="formInline" class="form-inline">
    <el-row class="row">
      <el-form-item label="文档名称：">
        <el-input
          v-model="formInline.fileName"
          placeholder="--请输入--"
        ></el-input>
      </el-form-item>
      <el-form-item label="文档类型：">
        <!-- <el-input
          v-model="formInline.fileType"
          placeholder="--请输入--"
        ></el-input> -->
        <el-select
          v-model="formInline.type"
          @change="change"
          placeholder="--请输入--"
          @click="select"
        >
          <el-option
            v-for="item in options.value"
            :key="item.label"
            :label="item.label"
            :value="item.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上传时间：">
        <el-date-picker
          v-model="formInline.time"
          type="datetimerange"
          :shortcuts="shortcuts"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          range-separator="~"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="change"
          size="small"
        />
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="success" @click="onClear">清空</el-button>
      </el-form-item>
    </el-row>
  </el-form>
</template>

<script setup>
import { ref, reactive, defineEmits } from 'vue'
import { getKonewType } from '@/api/reserveData'
const formInline = reactive({
  fileName: '',
  type: '',
  time: ''
})
const shortcuts = [
  {
    text: '上个星期',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    }
  },
  {
    text: '上个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    }
  },
  {
    text: '前三个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
      return [start, end]
    }
  }
]
const emits = defineEmits(['onSearch'])
const options = reactive({})

const onSubmit = () => {
  emits('onSearch', formInline)
}
const change = (options) => {
  console.log('options', options)
}
const onClear = () => {
  formInline.type = ''
  formInline.fileName = ''
  formInline.time = ''
  emits('onSearch', formInline)
}
const select = () => {
  getKType()
}
const getKType = async () => {
  const res = await getKonewType()
  let obj = {}
  for (let key in res) {
    obj[key] = res[key]
  }
  let newObj = Object.keys(obj).map((val) => ({
    label: obj[val]
  }))
  options.value = newObj
  console.log('newObj', newObj)
}
getKType()
</script>

<style lang="scss" scoped>
.form-inline {
  width: 100%;
  position: relative;
  // display: flex;
  // column-gap: 20px;
  // padding-bottom: 33px;
  .row {
    display: flex;
    column-gap: 5%;
  }
  .btns {
    position: absolute;
    right: 0;
    top: 1px;
    .m-left {
      margin-left: 20px;
    }
  }
}
</style>
